package com.tehmur.android.menuTest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;

public class splashScreen extends Activity {
	
	//boolean to check if user clicked to exit splash screen
	private boolean _active = true; 
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.splash);
		/* set time to splash out - time to display the splash screen in ms */
		final int _splashTime = 1500;
		
		/* create a thread to show splash up to splash time */
		Thread welcomeThread = new Thread() {

			@Override
			public void run() {
				try {
					super.run();
					/* use while to get the splash time. Use sleep() to increase
					 * the wait variable for every 100L.					 
					 */
					int waited = 0;
	                while(_active && (waited < _splashTime)) {
	                    sleep(100);
	                    if(_active) {
	                        waited += 100;
	                    }
	                }

				} catch (Exception e) {
					System.out.println("EXc=" + e);
				} finally {
					/**
					 * Called after splash times up. 
					 * Go to menu class after splash times up. 
					 */
					startActivity(new Intent(splashScreen.this,
							menuTest.class));
					finish();
				}
			}
		};
		welcomeThread.start();

	
}

	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			_active = false;
		}
		return true;
	}

}